package com.wheat.vipcard.bean;

import java.math.BigInteger;
import java.util.List;

import com.wheat.vipcard.HibernateSessionFactory;

import org.hibernate.Query;
import org.hibernate.Session;

/**
 * Data access object (DAO) for domain model
 * 
 * @author MyEclipse Persistence Tools
 */
public class BaseHibernateDAO implements IBaseHibernateDAO {

	public Session getSession() {
		return HibernateSessionFactory.getSession();
	}

	/**
	 * 返回总数
	 * 
	 * @param queryString
	 * @return
	 */
	public int queryCount(String sqlString) {
		String querySQL = "select count(1) from (" + sqlString + ") counts";
		Query query = getSession().createSQLQuery(querySQL);
		List<BigInteger> list = query.list();
		return list == null ? 0 : list.get(0).intValue();
	}

	/**
	 * 返回list
	 * 
	 * @param queryString
	 * @return
	 */
	public List<Object[]> queryList(String sqlString, int pageNo, int pageSize) {
		String querySQL = sqlString + " limit " + (pageSize * (pageNo - 1)) + "," + pageSize;
		return getSession().createSQLQuery(querySQL).list();
	}
}